SESSION = require('~coffee/_lib/session')

module.exports = (mod)->
    beforeRouteEnter = mod.beforeRouteEnter

    mod.beforeRouteEnter = (to, from, next)->
        if not (await SESSION.user())
            next(false)
            GO.ln('auth/login', to.path)
            return
        if beforeRouteEnter
            beforeRouteEnter.apply @,arguments
        else
            next()
    return mod
